﻿<?php
	/*
		Model nghệ sĩ
		1.0.1
		-------------------------------------------------------------------
		Hồng Hải
		03-10-2013
	*/
	
	include "connection.php";
	

	function insert_nghesi($ngheSi) {
		$p = array($ngheSi->getNgheDanh(), $ngheSi->getTenThat(), $ngheSi->getNgaySinh(), $ngheSi->getTieuSu());
		$query = "call them_nghe_si('".join("','", $array)."')";
		
		$connection = getConnection();
		mysqli_query($query, $connection) or die("SQL Error 1: " . mysqli_error());
		// đóng connection
		
		$result = mysql_insert_id();	// http://au.php.net/mysql_insert_id
		
		return $result;
	}
	
	function update_nghesi($ngheSi) {
		$p = array($ngheSi->getID(), $ngheSi->getNgheDanh(), $ngheSi->getTenThat(), $ngheSi->getNgaySinh(), $ngheSi->getTieuSu());
		$query = "call cap_nhat_thong_tin_nghe_si('".join("','", $array)."')";
		
		$connection = getConnection();
		$result = mysqli_query($query, $connection) or die("SQL Error 1: " . mysqli_error());
		// đóng connection
		
		return $result;
	}
	
	function delete_nghesi($maNgheSi) {
		$query = "call xoa_nghe_si('".$maNgheSi."')";
		
		$connection = getConnection();
		$result = mysqli_query($query, $connection) or die("SQL Error 1: " . mysqli_error());
		// đóng connection
		
		return $result;
	}
	
	function getSingersList($isLogedIn) {
		$query = "call danh_sach_nghe_si('$isLogedIn')";
		
		$connection = getConnection();
		$result = mysqli_query($query, $connection) or die("SQL Error 1: " . mysqli_error());
		
		return $result;
	}
	
	// Dùng cho khách, lượt like + 1
	function thich_nghesi($maNgheSi) {
		$query = "call thich_nghe_si('$maNgheSi')";
		
		$connection = getConnection();
		$result = mysqli_query($query, $connection) or die("SQL Error 1: " . mysqli_error());
		
		return $result;
	}
	
	// Cho nghệ sĩ rời công ty hoặc vào lại
	// parameter $conHoatDong mang giá trị True, False
	function hoatdong_nghesi($maNgheSi, $conHoatDong) {
		$query = "call hoat_dong_nghe_si('$maNgheSi', $conHoatDong)";
		
		$connection = getConnection();
		$result = mysqli_query($query, $connection) or die("SQL Error 1: " . mysqli_error());
		
		return $result;
	}
	
	class nghesi{
		private $id, $tenthat, $ngaysinh, $nghedanh, $luotlike, $conhoatdong, $tieusu;
		
		public function _construct($id, $nghedanh, $tenthat, $ngaysinh, $tieusu, $conhoatdong = true, $luotlike = 0) {
			$this->id = $id;
			$this->nghedanh = $nghedanh;
			$this->tenthat = $tenthat;
			$this->ngaysinh = $ngaysinh;
			$this->tieusu = $tieusu;
			$this->conhoatdong = $conhoatdong;
			$this->luotlike = $luotlike;
		}
		
		public function getID() {
			return $this->id;
		}
		
		public function setID($id) {
			$this->id = $id;
		}
		
		public function getTenThat() {
			return $this->tenthat;
		}
		
		public function setTenThat($tenthat) {
			$this->tenthat = $tenthat;
		}
		
		public function getNgheDanh() {
			return $this->nghedanh;
		}
		
		public function setNgheDanh($nghedanh) {
			$this->nghedanh = $nghedanh;
		}
		
		public function getNgaySinh() {
			return $this->ngaysinh;
		}
		
		public function setNgaySinh($ngaysinh) {
			$this->ngaysinh = $ngaysinh;
		}
		
		public function getTieuSu() {
			return $this->tieusu;
		}
		
		public function setTieuSu($tieusu) {
			$this->tieusu = $tieusu;
		}
		
		public function getLuotLike() {
			return $this->luotlike;
		}
		
		public function setLuotLike($luotlike) {
			$this->luotlike = $luotlike;
		}
		
		public function getConHoatDong() {
			return $this->conhoatdong;
		}
		
		public function setConHoatDong($conhoatdong) {
			$this->conhoatdong = $conhoatdong;
		}
	}
?>